#ifndef VIDEOCAPTURE_H
#define VIDEOCAPTURE_H

#include <QObject>
#include <QThread>
#include <atomic>


struct AVFormatContext;
struct AVCodecContext;
struct AVFrame;

class VideoCapture : public QThread
{
    Q_OBJECT
public:
    explicit VideoCapture(QObject *parent = nullptr);

    bool open(const QString &device_name);

    // 停止相机画面帧抓取，线程也将停止
    void close();

protected:
    void run() override;

private:
    // 打开解码器
    bool openDecoder();

    void read();
signals:
    // 发送图像帧
    void appending_frame(AVFrame*);

private:
    AVFormatContext *m_pCtx{nullptr};
    AVCodecContext* m_pDecoderCtx{nullptr};
    std::atomic_bool m_bLooping{false};
};

#endif // VIDEOCAPTURE_H
